package com.leetcode.p300;

public class Test343_2 {

    private int max3(int a1, int a2, int a3) {
        return Math.max(Math.max(a1, a2), a3);
    }

    public int integerBreak(int n) {
        if (n <= 2) {
            return 1;
        }

        int[] dp = new int[n + 1];
        dp[2] = 1;

        for (int i = 1; i <= n; i++) {
            int currentMax = 0;
            for (int j = 1; j < i - j + 1; j++) {
                currentMax = max3(currentMax, dp[i - j] * (j), j * (i - j));
            }
            dp[i] = currentMax;
        }

        return dp[n];
    }

    public static void main(String[] args) {
        Test343_2 test = new Test343_2();

//        63 = 9*7 或 3*3*7
//        891= 9*9*9
//        System.out.println(test.integerBreak(63));
        System.out.println(test.integerBreak(4));
    }
}
